package com.aloaproject.ciquta;

/**
 * That link{Criterion} is evaluated to true if the given property is == to the provided value.
 * @author Daniele Demichelis
 */
final class EqEqCriterion implements Criterion {

    private final Object expectedValue;
    private final String propertyPath;

    EqEqCriterion(final String propertyPath, final Object expectedValue) {
        this.expectedValue = expectedValue;
        this.propertyPath = propertyPath;
    }

    public final boolean match(final Object object) {
        try {
            Object value = org.apache.commons.beanutils.PropertyUtils.getProperty(object, propertyPath);
            return test(
                    expectedValue,
                    value);
        } catch (NoSuchMethodException ex) {
            return false;
        } catch (Exception ex) {
            throw new RuntimeException();
        }
    }

    private final boolean test(final Object expectedValue, final Object actualValue) {
        return (expectedValue == actualValue);
    }



}
